package annoation;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @Author: hmm
 * @Created: 2019/11/26
 * @Description:
 * @Modified by:
 */
@GoodLock(name = "test")
public class AnnoationMain {

    @Test
    public static void ta() {
        System.out.println("test");
    }

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        ClassLoader classLoader = AnnoationMain.class.getClassLoader();
        Annotation[] annotations1 = AnnoationMain.class.getAnnotations();
        Field[] declaredFields = AnnoationMain.class.getDeclaredFields();
        Method[] methods = AnnoationMain.class.getMethods();
        GoodLock goodLock = AnnoationMain.class.getAnnotation(GoodLock.class);
        Method[] methods1 = goodLock.annotationType().getMethods();
        for (Method m : methods) {
            Annotation[] declaredAnnotations = m.getDeclaredAnnotations();
            Annotation[] annotations = m.getAnnotations();
            if (declaredAnnotations.length > 0) {
                for (Annotation a : annotations) {
                    if (a instanceof Test) {
                        String author = ((Test) a).author();
                        System.out.println(author);
                    }
                }
            }
            Test annotation = m.getAnnotation(Test.class);
            System.out.println(m.getName() + "=====");
            if (annotation != null) {
                System.out.println(annotation.author());
                System.out.println(annotation.mine());
            }
        }

        for (Method m : methods1) {
            System.out.println(m.getAnnotatedReturnType());
            System.out.println(m.getDeclaredAnnotations());
            System.out.println(m.getDeclaringClass());
        }
    }
}
